package com.zxb.core.auth;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.zxb.core.common.R;
import com.zxb.core.util.JsonUtil;
import com.zxb.core.util.TokenUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zxb
 */
@RestController
@AllArgsConstructor
@Slf4j
public class ThirdController {

    /**
     * 获取accessToken，需要进行安全验证
     */
    @PostMapping("/un/accessToken/generate")
    @Safe
    public R<ObjectNode> generateAccessToken(String appKey, String appSecret) {
        String accessToken = TokenUtil.createSafeToken(appKey, appSecret);
        ObjectNode on = JsonUtil.on();
        on.put("accessToken", accessToken);
        on.put("expiry", TokenUtil.SAFE_TOKEN_EXPIRE);
        return R.success(on);
    }
}
